from PIL import Image


# 将彩色图片转换为黑白图片
def black_and_white_image(image_path, save_path):
    # 打开原始彩色图像文件
    image = Image.open(f'{image_path}')

    # 将彩色图像转换为黑白图像
    black_white_image = image.convert(mode='L')

    # 保存黑白图像到新文件
    black_white_image.save(save_path)


if __name__ == '__main__':
    image_path = r"/Users/admin/Downloads/主题1.PNG"
    save_path = r'/Users/admin/Downloads/主题2.PNG'
    black_and_white_image(image_path, save_path)
